Skip to content

VFR: separate frame positions and durations - #591

Draft
MuhammadBilalKhan267 wants to merge 44 commits into
Breakthrough:mainfrom
MuhammadBilalKhan267:fix/569-vfr-inaccurate-frame-nums
Draft

MuhammadBilalKhan267 wants to merge 44 commits into
Breakthrough:mainfrom
MuhammadBilalKhan267:fix/569-vfr-inaccurate-frame-nums

Conversation

@MuhammadBilalKhan267

@MuhammadBilalKhan267 MuhammadBilalKhan267 commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Separate frame ordinals from presentation timestamps to address #569.

VFR frame numbers were derived from timestamps and average frame rate. This PR counts frames independently and ports the library to FramePosition and FrameDuration for 0.8.

Changes

  • Add FramePosition for frame ordinals and timestamps, and FrameDuration for frame counts and elapsed time
  • Port backends, stream wrappers, detectors, SceneManager and StatsManager
  • Add explicit RELATIVE and SOURCE numbering and non-consuming timestamp peeking
  • Separate reported source duration from frame count
  • Port CLI commands, outputs, image extraction and paired CSV loading
  • Remove FrameTimecode and retain selected forwarding helpers on FramePosition
  • Update tests, benchmarks, scripts, API examples and migration guidance

Remaining work

Status Item Scope
⬜ Final-frame duration and exclusive end timestamps Fix in this PR
🟡 Threshold midpoint selection when frames are skipped Agree on behavior before merge
🟡 CSV loading restrictions and range limits Agree on behavior before merge
🟡 Negative durations and recoverable timestamp errors Agree on behavior before merge
⬜ Shared VFR golden baselines Separate resources PR coordinated with this change

Deferred

  • Exact VFR image padding and sampling
  • Image filename ordinals after relative seeks
  • Duration-based callback buffering
  • Native timing improvements for MoviePy and capture adapters

- Centralize frame numbering and position tracking in VideoStream.
- Update backend reads, seeks, resets, and stream wrappers.
- Migrate StatsManager and ThresholdDetector to FramePosition.
- Add shared input parsing, exact time calculations, and local fade buffering.
- Preserve frame/time minimum units through shared input parsing.
- Check frame counts or exact elapsed time without FPS conversion.
- Retain original frame positions for delayed cuts.
- Update the SceneDetector contract and related documentation.
@MuhammadBilalKhan267

Copy link
Copy Markdown
Collaborator Author

FlashFilter and the base SceneDetector interface are now ported to FramePosition. Minimum-length checks use FrameDuration, preserving whether the input specifies frames or elapsed time. FPS conversions have been removed from these checks, while the MERGE/SUPPRESS state transitions remain unchanged.

The existing 240-FPS estimate remains for callback-image buffering. It does not control cut-duration checks. Removing it requires coordinated changes to SceneManager and detector buffer handling, so that work is deferred until the SceneManager port.

- Replace FrameTimecode with FramePosition for detector inputs and returned cuts.
- Rename timecode parameters to position in ContentDetector and FlashFilter.
- Preserve frame positions in the rolling buffer, detected cuts and stats.
- Parse minimum scene lengths once and compare frames or exact elapsed time.
- Add SceneDetector.meets_minimum for frame and time comparisons.
- Preserve frame positions in detected cuts and stats.
- Parse minimum scene lengths once and use the inherited duration check.
- Preserve frame positions in detected cuts and stats.
- Parse minimum scene lengths once and use the inherited duration check.
- Preserve original frame positions through prediction buffers and detected cuts.
- Remove PTS/FPS-based timecode reconstruction.
- Run FlashFilter once per real prediction, including non-cut frames.
- Mark startup and EOF padding with None to exclude artificial frames from cut detection and filter state.
@MuhammadBilalKhan267

Copy link
Copy Markdown
Collaborator Author

Ported all detectors to FramePosition. Added SceneDetector.meets_minimum() to compare a duration against a parsed minimum in frames or seconds.

TransNet now passes every real prediction through FlashFilter, including non-cut frames needed to complete MERGE filtering.

- Use FramePosition for scene boundaries and callbacks.
- Add peek_timecode across backends and stream wrappers.
- Check frame/time limits before every read, including skipped frames.
- Report progress in frames or seconds.
- Forward detect() inputs directly and align position-pair aliases.
- Update documentation for the changed contracts.
@MuhammadBilalKhan267

Copy link
Copy Markdown
Collaborator Author

Ported SceneManager to FramePosition and added peek_timecode() across all backends and wrappers. Cutoff checks, progress reporting, and detect() are updated. CLI, outputs, and test migration are next.

Comment thread scenedetect/common.py Fixed
Comment thread scenedetect/video_stream.py Dismissed
- Port CSV, HTML, EDL, FCPXML, FCP7, and OTIO writers.
- Use frame ordinals for frame fields and timestamps for time fields.
- Preserve rational timing until output formatting.
- Update scene metadata, filename formatting, and video splitting.
- Pass the export frame rate explicitly from the EDL CLI command.
- Handle empty scene lists in HTML output.
@MuhammadBilalKhan267

Copy link
Copy Markdown
Collaborator Author

Ported CSV, HTML, EDL, FCPXML, FCP7, OTIO, and video splitting to the new types. Frame fields now use ordinals, while timing comes from timestamps.

- Generate exact Timecode targets from scene timestamps.
- Calculate image counts using frame or time intervals without FPS conversion.
- Use decoded frame positions for filenames in both extraction paths.
- Remove the floating-point interval tolerance.
- Temporarily use zero padding for integer margins and document the deferred VFR policy.
- Preserve frame and time units when parsing CLI inputs
- Add configurable frame numbering and update detection limits
- Port CLI output handlers and scene postprocessing
- Load paired frame numbers and timestamps from scene CSVs
- Export Timecode, FramePosition, and FrameDuration
[api] Separate stream metadata and support expanded splits [skip ci]

- Separate duration seconds from reported frame counts across backends
- Update CLI validation, logging, progress, and editor duration exports
- Preserve the source cursor when creating fan-out consumers
- Expand split commands to source start and EOF without rebuilding scene positions
- Honor configured expansion and format expanded filename boundaries as zero/open-ended
Use FramePosition.frame_number in benchmark predictions, parameter
sweeps, and golden cut-list generation.
- Forward timestamp formatting, timing properties, and legacy getters
- Add deprecated frame_num alias and ordering by frame_number
- Preserve FramePosition and exact Timecode arithmetic
- Restore frame-rate-based image margins and port the Breakthrough#608 clamp
- Retain upstream weight validation and formatter regression tests
- Follow the arithmetic protocol for unsupported operands
- Update negative-result tests to expect ArithmeticError
- Remove unused imports and redundant code, and fix test typing
- Update API examples, migration guidance, and generated CLI docs
- Preserve the FramePosition API while incorporating upstream updates
- Port the new image-resizing test to FramePosition
Comment thread scenedetect/_cli/controller.py Fixed
Comment thread scenedetect/common.py Dismissed
Comment thread tests/test_frame_position.py Dismissed
Comment thread tests/test_frame_position.py Dismissed
Comment thread tests/test_scene_manager.py Dismissed
- Pass source end frames directly to detect()
- Use valid PNG compression in the resizing test
- Remove a redundant CSV range comparison

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants